<template>
  <AuditShowPage
    :formData="formData"
    :formItems="formItems"
    :handleFail="handleAuditFail"
    :handleSuccess="handleAuditSuccess"
    @goback="handleGoBack"
  >
    <h3 slot="page-header">计量单位待审核-查看</h3>
  </AuditShowPage>
</template>
<script>
import AuditShowPage from '@/components/AuditShowPage';
import { isResponseSuccess } from '@/utils/bizUtils';
import {
  baseGetByUuidService,
  auditNoPassService,
  auditPassService
} from '@/api/basics/unitManage/unitToAudit';
export default {
  components: {
    AuditShowPage
  },
  data () {
    return {
      formData: {},
      formItems: [
        {
          prop: 'unitName',
          label: '计量单位名称'
        },
        {
          prop: 'unitGroupName',
          label: '计量单位组'
        },
        {
          prop: 'decimalPlaces',
          label: '默认小数位'
        },
        {
          prop: 'note',
          label: '备注'
        },
      ],
      uuid: ''
    }
  },
  mounted () {
    this.uuid = this.$route.query?.uuid
    this.getPageDetails()
  },
  methods: {
    async getPageDetails () {
      const data = { uuid: this.uuid }
      const res = await baseGetByUuidService(data, '.page-body')
      if (res?.retData) {
        this.formData = res.retData
      }
    },
    // 返回
    handleGoBack () {
      this.$router.push({ name: 'skuRelAuditList' })
    },
    // 审核不通过
    async handleAuditFail (loadingFn, messageFn, dataSource) {
      const data = { uuids: this.uuid, auditNote: dataSource?.reason }
      const res = await auditNoPassService(data, loadingFn)
      if (isResponseSuccess(res)) {
        messageFn()
        this.handleGoBack()
      }
    },
    // 审核通过
    async handleAuditSuccess (loadingFn, messageFn, dataSource) {
      const data = { uuids: this.uuid, auditNote: dataSource?.reason }
      const res = await auditPassService(data, loadingFn)
      if (isResponseSuccess(res)) {
        messageFn()
        this.handleGoBack()
      }
    },
  }
}
</script>
